package cn.org.july.weixin.service.event.listener;

import cn.org.july.weixin.common.bean.message.TextMessage;
import cn.org.july.weixin.common.constant.EventType;
import cn.org.july.weixin.common.constant.WxConstant;
import cn.org.july.weixin.service.event.Event;
import cn.org.july.weixin.service.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @auther: wanghongjie
 * @blame: wanghongjie
 * @date: 2020-09-03 07:00
 * @Description:
 */
@Service
public class ClickListener implements EventListener {
    @Override
    public String handleEvent(Event event) {
        Map<String, Object> message = event.getMessage();
        String eventType = message.get(WxConstant.EVENT).toString();
        if (EventType.eventType(eventType) == EventType.CLICK) {
            return TextMessage.ofSendMsg(message, message.get(WxConstant.EVENT_KEY).toString()).toXml();
        }
        return null;
    }

    @Override
    public EventType getEvent() {
        return EventType.CLICK;
    }
}
